require("dotenv").config();
const session = require("express-session");

const setSession = session({
    secret: process.env.session_secret,
    resave: false,
    saveUninitialized: false,
    cookie: {
        secure: false,
        maxAge: 1000 * 60 * 60 * 24, // 1天
        httpOnly: true,
    }
});
const sessionMiddleware = (req, res, next) => {
    req.session.isLogin = req.session.isLogin || false;
    req.session.views = (req.session.views || 0) + 1;
    next();
};

module.exports = {
    sessionMiddleware,
    setSession
};
